﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class UserWork_NewUserInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
            con.Open();
            string sql = "select * from branch";
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            Branch.DataSource = ds;
            Branch.DataTextField = "Branch";
            Branch.DataValueField = "Dutyid";
            Branch.DataBind();
            con.Close();
                SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
                con1.Open();
                string sql1 = "select * from Employee where username='"+Session["UserName"].ToString()+"'";
                SqlCommand com1 = new SqlCommand(sql1, con1);
                SqlDataReader dr1 = com1.ExecuteReader();
                dr1.Read();    
                name.Text = dr1["name"].ToString();
                sex.Items.FindByValue(dr1["sex"].ToString()).Selected = true;
                Marry.Items.FindByValue(dr1["Marry"].ToString()).Selected = true;
                Branch.Items.FindByValue(dr1["Dutyid"].ToString()).Selected = true;
                Birthday.Text = dr1["Birthday"].ToString();
                Stature.Text = dr1["Stature"].ToString();
                Avoirdupois.Text = dr1["Avoirdupois"].ToString();
                cardtype.Text = dr1["cardtype"].ToString();
                cardid.Text = dr1["cardid"].ToString();
                Speciality.Text = dr1["Speciality"].ToString();
                workPhone.Text = dr1["workPhone"].ToString();
                movePhone.Text = dr1["movePhone"].ToString();
                HomePhone.Text = dr1["HomePhone"].ToString();
                xiaolingtong.Text = dr1["xiaolingtong"].ToString();
                Homeaddress.Text = dr1["Homeaddress"].ToString();
                Post.Text = dr1["Post"].ToString();
                url.Text = dr1["url"].ToString();
                Email.Text = dr1["Email"].ToString();
                qq.Text = dr1["qq"].ToString();
                msn.Text = dr1["msn"].ToString();

                con1.Close();
        
       

        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string names = this.name.Text;
        int dutyid = Convert.ToInt32(Branch.SelectedItem.Value.ToString());
        string branch = Branch.SelectedItem.Text;
        string sexs = sex.SelectedItem.Text;
        string Marrys = Marry.SelectedItem.Text;
        string Birthdays = Birthday.Text.Trim();
        string Statures = Stature.Text.Trim();
        string Avoirdupoiss = Avoirdupois.Text.Trim();
        string cardtypes = cardtype.SelectedItem.Text;
        string cardids = cardid.Text.Trim();
        string Specialitys = Speciality.Text.Trim();
        string addTime = DateTime.Now.ToShortDateString();
        string workPhones = workPhone.Text.Trim();
        string movePhones = movePhone.Text.Trim();
        string HomePhones = HomePhone.Text.Trim();
        string xiaolingtongs = xiaolingtong.Text.Trim();
        string Homeaddresss = Homeaddress.Text.Trim();
        string Posts = Post.Text.Trim();
        string urls = url.Text.Trim();
        string Emails = Email.Text.Trim();
        string qqs = qq.Text.Trim();
        string msns = msn.Text.Trim();
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        con.Open();

        string sql = "update Employee set  Name='" + names + "',sex='" + sexs + "',Marry='" + Marrys + "',Birthday='" + Birthdays + "'," +
            "Stature='" + Statures + "',branch='" + branch + "',Avoirdupois='" + Avoirdupoiss + "',cardtype='" + cardtypes + "',cardid='" + cardids + "'," +
            "Speciality='" + Specialitys + "',workPhone='" + workPhones + "',movePhone='" + movePhones + "',HomePhone='" + HomePhones + "'," +
            "xiaolingtong='" + xiaolingtongs + "',Homeaddress='" + Homeaddresss + "',Post='" + Posts + "',url='" + urls + "'," +
            "Email='" + Emails + "',qq='" + qqs + "',msn='" + msns + "' where username='"+Session["UserName"].ToString()+"' ";
        SqlCommand com = new SqlCommand(sql, con);
        com.ExecuteNonQuery();
        Response.Write("<script>alert('修改成功!');window.location.href='../Main.aspx';</script>");
        con.Close();
    }
}
